@extends('admin.layouts.app')
@section('css')
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
     <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=c5dac0d4761d48c299d7d86a9a84458b&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder">
     </script>
      <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <script type="text/javascript" src="/js/plupload.full.min.js"></script>  
@endsection
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">点位管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="#">系统</a></li>
                                    <li><a href="{{url('zadmin/billboard')}}">点位管理</a></li>
                                    <li class="active">修改点位</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                          <div class="col-lg-12">
                            <div class="card-box">
                            <h2 class="m-t-0 header-title">修改点位</h2>
                            <hr/>
                             @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif

                              <div class="row">
                                <div class="col-md-6">
                                   <form class="form-horizontal" role="form" action="{{url('zadmin/billboard/'.$data->id)}}" method="post">
                                    {{ method_field('PUT') }}
                                            

                                              <div class="form-group">
                                                  <label class="control-label">名称</label>
                                                 
                                                      <input type="text" class="form-control" name="title" required="" value="{{$data->title}}">
                                                
                                              </div>
                                             
                                                   
                                                      
                                                  
                                             
                                              
                                              <div class="form-group">
                                                  <label class="control-label">编号</label>
                                                  
                                                       <input  class="form-control" name="code" value="{{$data->code}}" >
                                                  
                                              </div>
                                              

                                              <div class="form-group">
                                                  <label class="control-label">区域</label>
                                                  
                                                      <input  class="form-control" name="address" value="{{$data->address}}" >
                                                       
                                                 
                                              </div>
                                              <div class="form-group">
                                                  <label class="control-label">大包价格</label>
                                                  
                                                      <input  class="form-control" name="big_price" value="{{$data->big_price}}" >
                                                       
                                                 
                                              </div>
                                              <div class="form-group">
                                                  <label class="control-label">小包价格</label>
                                                  
    <input  class="form-control" name="small_price" value="{{$data->small_price}}" >
                                                       
                                                 
                                              </div>
    <div class="form-group">
      <label class="control-label">营业时间</label>                                                  
      <input value="{{$data->work_time}}"  class="form-control" name="work_time" placeholder="用空格分割" >
                                                       
                                                 
    </div>

    

    
    
                   

                    <div class="form-group">
                    <label class="control-label">上传图片</label>
                    
                      <div id="filelist"></div>

                      <div class="piclist"></div>
                                                                   
                    <button class="btn" type="button" id="pickfiles">选择图片</button>
                 
                                                       
                                                 
                </div> 

                    <div class="form-group">
                        <label class="control-label">图片</label>                                   
                        <div class="row"> 

                          @foreach($data->pics as $pic)
                          <div class="col-md-4">
                            <img src="{{$pic->pic}}"  height="120" />
                            <p>
                            <a href="{{url('zadmin/bp-thumb')}}?billboard_id={{$data->id}}&pic={{$pic->pic}}" class="btn btn-info">封面</a>
                            <a href="{{url('zadmin/bp-delete',$pic->id)}}" class="btn btn-danger">删除</a>
                          </p>
                          </div>
                          @endforeach
                        </div>  
                        
                                                       
                                                 
                    </div>                                        

                                            
                                                                                                                 
                                             

                                              <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info">保存</button>
                                              </div>
                                              
                             <input type="hidden" class="form-control" name="lnglat" id="lnglat" required="" value="{{$data->lnglat}}">   <input name="pics" id="pics" type="hidden" value=""  />                 
                             {{csrf_field()}}
                                          </form>
                                </div>

                                <div class="col-md-6" style="padding: 10px;">
                                  <div id="container" style="height: 500px;"></div>
                                    <div id="myPageTop">
                                        <table>
                                            <tr>
                                                <td>
                                                    <label>请输入关键字：</label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <input id="tipinput"/>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>                                  
                                </div>

                              </div>

                             
                              
                              
                            </div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
      
       

           



    
        @section('js')

        <script type="text/javascript">
        pics = '';
          var uploader = new plupload.Uploader({
              runtimes : 'html5,flash,silverlight,html4',
              browse_button : 'pickfiles', // you can pass an id...
              container: document.getElementById('container'), // ... or DOM Element itself
              url : '/upload.php',
              flash_swf_url : '../js/Moxie.swf',
              silverlight_xap_url : '../js/Moxie.xap',
              
              filters : {
                max_file_size : '10mb',
                mime_types: [
                  {title : "Image files", extensions : "jpg,gif,png"},
                  {title : "Zip files", extensions : "zip"}
                ]
              },

              init: {
                PostInit: function() {
                  $('#filelist').html('');

                  
                },

                FilesAdded: function(up, files) {
                  plupload.each(files, function(file) {
                    $('#filelist').html('<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>');
                     uploader.start();
                     return false;
                  });
                },

               

                 FileUploaded: function(up, file, info) {
                            // Called when file has finished uploading
                              var rs =  JSON.parse(info.response);
                              if(rs.status){
                                //console.info(rs.data);
                                var str = '<img style="padding:5px" src="'+rs.data+'" width="100">';
                                $('.piclist').append(str);
                                pics += rs.data+',';
                                $('#pics').val(pics);
                              }
                              console.info(rs);
                              
                },

                
                 

                
              }
            });

uploader.init();          
         
        var geocoder = new AMap.Geocoder({
              // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
              city: '厦门'

        })
        //地图加载
        var map = new AMap.Map("container", {
            resizeEnable: true,           
        });

         var center = [];
         var zoom = 12;   
         @if($data->lnglat)
         center = "{{$data->lnglat}}".split(',');        

         zoom = 14;
         map.setCenter(center);
         map.setZoom(zoom);
         marker = new AMap.Marker({
                 // icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
                  position: center,
                  offset: new AMap.Pixel(-13, -30)
              });
              marker.setMap(map);
         @endif

          
          //输入提示
          var autoOptions = {
              input: "tipinput"
          };
          var auto = new AMap.Autocomplete(autoOptions);
          var placeSearch = new AMap.PlaceSearch({
              map: map
          });  //构造地点查询类
          AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
          function select(e) {
              placeSearch.setCity(e.poi.adcode);
              placeSearch.search(e.poi.name);  //关键字查询查询
          }

          map.on('click', function(e) {
              markers = map.getAllOverlays('marker');
              if(markers) {
                map.remove(markers)
              }
              document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
              lnglat = e.lnglat;
              marker = new AMap.Marker({
                  icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
                  position: lnglat,
                  offset: new AMap.Pixel(-13, -30)
              });
              marker.setMap(map);
              geocoder.getAddress(lnglat, function(status, result) {
              if (status === 'complete' && result.info === 'OK') {
                  var address = result.regeocode.formattedAddress;
                  $('input[name="address"]').val(address);
              }
            })
          });


        </script>

     
         

          
       
        @endsection
    
